//
// Created by enemy1205 on 2021/8/12.
//
#include "identity.h"

using namespace std;

void teacher::ID_init(string &name, string &passport, int &num) {
    cout << "您现在以教师的身份操作" << endl;
    get_name() = name;
    get_passport() = passport;
    this->tea_num = num;
}

void teacher::showAllOrder() {
    OrderFile OF;
    if (OF.m_Size == 0) {
        cout << "无预约记录" << endl;
        getchar();
        return;
    }

    for (int i = 0; i < OF.m_Size; i++) {
        cout << i + 1 << "、 ";
        /*利用关键字进行索引*/
        cout << "预约日期： 周" << OF.m_orderData[i]["date"];
        cout << " 时段：" << (OF.m_orderData[i]["interval"] == "1" ? "上午" : "下午");
        cout << " 学号：" << OF.m_orderData[i]["stuId"];
        cout << " 姓名：" << OF.m_orderData[i]["stuName"];
        cout << " 机房：" << OF.m_orderData[i]["roomId"];
        string status = " 状态： ";  // 0 取消的预约   1 审核中   2 已预约 -1 预约失败
        if (OF.m_orderData[i]["status"] == "1") {
            status += "审核中";
        } else if (OF.m_orderData[i]["status"] == "2") {
            status += "预约成功";
        } else if (OF.m_orderData[i]["status"] == "-1") {
            status += "审核未通过，预约失败";
        } else {
            status += "预约已取消";
        }
        cout << status << endl;
    }

    getchar();
}

void teacher::validOrder() {
    OrderFile OF;
    this->showAllOrder();
    string select_id;
    cout << "请输入要审核预约记录的学号,0代表返回" << endl;
    cin >> select_id;
    if (select_id == "0") return;
    for (auto it = OF.m_orderData.begin(); it != OF.m_orderData.end(); ++it) {
        if (it->second["stuId"] == select_id) {
            int ret;
            cout << "请输入审核结果" << endl;
            cout << "1、通过" << endl;
            cout << "2、不通过" << endl;
            cin >> ret;
            if (ret == 1) it->second["status"] = "2";
            else it->second["status"] = "-1";
            OF.updateOrder();
            cout << "审核完毕！" << endl;
            return;
        }
    }

}

void teacher::operMenu(const string &name, Manager *) {
    cout << "欢迎教师：" << name << "登录！" << endl;
    while (true) {
        cout << "\t\t ----------------------------------\n";
        cout << "\t\t|                                  |\n";
        cout << "\t\t|          1.查看所有预约            |\n";
        cout << "\t\t|                                  |\n";
        cout << "\t\t|          2.审核预约               |\n";
        cout << "\t\t|                                  |\n";
        cout << "\t\t|          0.注销登录               |\n";
        cout << "\t\t|                                  |\n";
        cout << "\t\t ----------------------------------\n";
        cout << "请选择您的操作： " << endl;
        int select = 0;
        cin >> select;
        if (select == 1) {
            //查看所有预约
            this->showAllOrder();
            getchar();

        } else if (select == 2) {
            //审核预约
            this->validOrder();
            getchar();
        } else {
            cout << "注销成功" << endl;
            return;
        }
    }
}